<?php
namespace Application\Model\Dao;

use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\ResultSet\ResultSet;
class FileDao extends BaseDao
{
    public static $INSERT = "insert into photo(title, uploader, data) values (?, ?, ?)";
    
    public static $GET = "select * from photo where id = ?";
    
    public function saveProfileImage($title, $uploader, $data){
        $stmt = $this->adapter->createStatement(FileDao::$INSERT, array($title ,  $uploader, $data));
        $stmt = $stmt->prepare();
        $stmt->execute();
        $id = $this->adapter->driver->getConnection()->getLastGeneratedValue();
        $stmt = null;
        return $id;
    }
    
    public function getProfileImage($id){
        $stmt = $this->adapter->createStatement(FileDao::$GET, array($id));
        $stmt->prepare();
        $result = $stmt->execute();
        if ($result instanceof ResultInterface && $result->isQueryResult()) {
            $resultSet = new ResultSet();
            $resultSet->initialize($result);
            foreach ($resultSet as $user) {
                return $user;
            }
            return $resultSet;
        }
    }
}

?>